package tree.Huffman.decodingAndCoding;

import org.junit.Test;
import tree.Huffman.decodingAndCoding.HuffmanTree_DataCompense;

import javax.management.NotificationEmitter;
import java.util.*;

public class MyTest {
    @Test
    public void testHuffman(){

        String sentence="tomorrow";
        HuffmanTree_DataCompense compense = new HuffmanTree_DataCompense();

        List<Node> list = compense.weightCal(sentence);
        Node root = compense.createEncodingTree(list);
        compense.encoding(root,new StringBuilder());
        Map<Character, String> encodingTable = compense.getEncodingTable();

        String toencoding = compense.toencoding(sentence);
        //编码表
        Set<Character> keySet = encodingTable.keySet();
        for(char key:keySet){
            System.out.println(key+":"+encodingTable.get(key));
        }

        System.out.println(toencoding);

        Collection<String> values = encodingTable.values();
        System.out.println("values集合");
        for (String C:values){
            System.out.println(C);
        }


        String decoding = compense.decoding(toencoding);
        System.out.println("解码:");
        System.out.println(decoding);
    }
    public void show(List<Node> list){
        for (int i=0;i< list.size();i++){
            System.out.println(list.get(i));
        }
    }


}
